﻿using System.Collections.Generic;
using System.Windows.Documents;
using System.Windows.Markup;
using RG.Common.WPF.Reporting.XPS_Utils;

namespace RG.Common.WPF.Reporting
{
    public static class DocMerger
    {
        public static FixedDocumentSequence SplitedDoc(IEnumerable<FixedDocumentSequence> docs)
        {
            var documentRollUp = new RollUpDocument();
            var sourcePages = new List<PageItem>();
            foreach (var sequence in docs)
                foreach (var docRef in sequence.References)
                {
                    var item = new DocumentItem(docRef.Name, docRef);
                    foreach (PageContent pageContent in item.FixedDocument.Pages)
                        sourcePages.Add(new PageItem(pageContent));
                }
            var ix = documentRollUp.AddDocument();
            foreach (var item in sourcePages)
                documentRollUp.AddPage(ix, item.PageContent.Source, (item.PageContent as IUriContext).BaseUri);
            return documentRollUp.FixedDocumentSequence;
        }
    }
}
